package com.limox.bishe.activity;

import com.limox.bishe.R;
import com.limox.bishe.app.APP;
import com.limox.bishe.db.DataBaseManager;
import com.limox.bishe.util.Util;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class Setting extends Activity {
	TextView text_weeknow;
	TextView text_nowweek;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);

		// 设置当前周数
		text_weeknow=(TextView)findViewById(R.id.text_weeknow);
		text_nowweek=(TextView)findViewById(R.id.text_nowweek);
		text_nowweek.setText("当前周数："+String.valueOf(APP.getWeekNow()));
		SeekBar seekbar = (SeekBar) findViewById(R.id.seekBar_nowweek);
		seekbar.setMax(APP.getWeekCount()-1);
		seekbar.setProgress(APP.getWeekNow());
		seekbar.setOnSeekBarChangeListener(mSeekBarChangeLisener);
		
		
		
		//切换用户
		LinearLayout linear_changeuser = (LinearLayout) findViewById(R.id.linear_changeuser);
		linear_changeuser.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//清除用户信息
				Util.SharedPerferencesCreat(Setting.this,"jwinfo","user_name","null");
				Util.SharedPerferencesCreat(Setting.this,"kb_info","kb_all","null");
				//清除数据库信息
				SQLiteDatabase SQLdb = DataBaseManager.OpenDb(Setting.this, "kb", null, 3);
				DataBaseManager.DeleteTb(SQLdb,"my_kb");
				
				
				Intent goIntent = new Intent();
				goIntent.setClass(Setting.this, LoginActivity.class);
 				startActivity(goIntent);
 
 				finish();
			}
		});
		
		
		
		//设置ActionBar
		ActionBar actionbar=getActionBar();
		actionbar.setDisplayUseLogoEnabled(false);
		actionbar.setDisplayHomeAsUpEnabled(true);
		actionbar.setTitle("设置");
		
		 
	}

	/**
	 * 设置当前周数的监听器
	 */
	private OnSeekBarChangeListener mSeekBarChangeLisener = new OnSeekBarChangeListener() {

		@Override
		public void onStopTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onStartTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			// TODO Auto-generated method stub
			int Strength = seekBar.getProgress();
//			 
//			
//			int width=(seekBar.getWidth()/seekBar.getMax())*progress; 
//			
// 			
// 			
//			text_weeknow.setLayoutParams(new LinearLayout.LayoutParams(width, LayoutParams.WRAP_CONTENT));
//			
//			text_weeknow.setText(String.valueOf(progress+1));
//			 
			APP.SetWeekNow(progress+1);
			text_nowweek.setText("当前周数："+String.valueOf(progress+1));
			
		}
	};
	
	
	@Override 
	public boolean onOptionsItemSelected(MenuItem item) { 
	  switch (item.getItemId()) { 
	     case (android.R.id.home) : 
	        finish();
	       return true; 
	     default: 
	       return super.onOptionsItemSelected(item); 
	  } 
	}

}
